package com.launcher.wkang.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.launcher.wkang.R;
import com.launcher.wkang.bean.TimeBean;
import com.launcher.wkang.util.CurriculumUtil;

import java.util.List;

public class MorningTimeAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mLayoutInflater;
    private List<TimeBean> timeLists;
    public MorningTimeAdapter(Context context){
        mContext=context;
        mLayoutInflater=LayoutInflater.from(context);
    }
    public void setData(List<TimeBean>list){
        timeLists=list;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return timeLists==null? 0:timeLists.size();
    }

    @Override
    public Object getItem(int position) {
        return timeLists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView==null){
            viewHolder=new ViewHolder();
            convertView=mLayoutInflater.inflate(R.layout.item_courle,null);
            viewHolder.coueseData=convertView.findViewById(R.id.courle_data);
            convertView.setTag(viewHolder);
        }else {
            viewHolder=(ViewHolder) convertView.getTag();
        }
//        viewHolder.coueseData.setText(timeLists.get(position).getStartTime().substring(0,5));
//        viewHolder.coueseData.setText(timeLists.get(position).getStartTime().substring(0,5));

        String courseName=timeLists.get(position).getStartTime().substring(0,5);
        String[] timeArgument=courseName.split(":");
        if (null!=timeArgument&&timeArgument.length>1){
            String hour=timeArgument[0];
            String minute=timeArgument[1];
            int hourInt=Integer.parseInt(hour);
            int minuteInt=Integer.parseInt(minute);
            CurriculumUtil.curriculumProhibit(hourInt,minuteInt,mContext,true);
            CurriculumUtil.curriculumProhibit(hourInt,minuteInt+45,mContext,false);
        }
        if (!TextUtils.isEmpty(courseName)){
            viewHolder.coueseData.setText(courseName);
        }else {
            viewHolder.coueseData.setText("   ");
        }

        return convertView;
    }
    private class ViewHolder{
        private TextView coueseData;
    }
}
